module JobsHelper
  def format_chemical_formula(formula)
    formula.gsub(/(\d+)/, '<sub>\1</sub>')
  end

  def format_mass(mass)
    (APP_CONFIG['format_mass'] % mass).gsub('-', '&#8209;').gsub(' ', '&nbsp;')
  end

  def format_diff(diff)
    (APP_CONFIG['format_diff'] % diff).gsub('-', '&#8209;').gsub(' ', '&nbsp;')
  end

  def format_score(score)
    APP_CONFIG['format_score'] % ((1.0 - score) * 100)
  end

  def sortable_table_header(peaknum, attribute)
    param, css_class = case params["o#{peaknum}"]
                       when "#{attribute}A" then ["#{attribute}D", "headerSortDown"]
                       when "#{attribute}D" then ["#{attribute}A", "headerSortUp"]
                       else ["#{attribute}D", nil]
                       end

    content_tag :th, :class => "header #{css_class}", :title => t(".tooltip.#{attribute}") do
      link_to(t(".#{attribute}"),
              edit_job_path(@job, params.merge("o#{peaknum}" => param, :anchor => "peak-#{peaknum}")))
    end
  end
end
